package sctu.edu.java.year2016.team08.lisonghong.day20160616.chapter11_3;

/**
 * Created by 松红 on 2016/6/16.
 * 创建Computer类，该类中有一个计算最大公约数的方法，如果向该方法传递负整数，该方法就会抛出自定义异常
 */
public class Computer1 {
    int n;

    public void divisor(int a, int b) throws MyException {
        if (a < 0 && b < 0) {
            throw new MyException();
        }
        if (a > b) {
            n = b;
        } else {
            n = a;
        }
        while (n-- >= 1) {
            if (a % n == 0 && b % n == 0)
                break;
        }
        System.out.println("最大的公约数为：" + n);
    }

    public static void main(String[] args) {
        try {
            Computer1 computer1 = new Computer1();
            computer1.divisor(6, 9);
        } catch (MyException e) {
            e.printStackTrace();
        }
    }
}
